package com.tuteng.administrator.ashospital.Activity;

import android.content.Intent;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.tuteng.administrator.ashospital.AdapterManger.Lis_jydjAdapter;
import com.tuteng.administrator.ashospital.JsonCallback;
import com.tuteng.administrator.ashospital.R;
import com.tuteng.administrator.ashospital.beans.GetLisJysqResponse;
import com.tuteng.administrator.ashospital.beans.Lis_jysqList;
import com.tuteng.administrator.ashospital.beans.Lis_jysqRequest;

import java.io.Serializable;
import java.util.List;

import static com.tuteng.administrator.ashospital.Config.GlobleConfig.APP_URL;

public class Lis_JydjActivity extends BaseActivity implements View.OnClickListener{
private TextView mNodata;
private LinearLayout mLjydj;
private  LinearLayout  mLtitle;
private ListView mListView;
private TextView mTextTitle;
private ImageButton mImageBack;
private Lis_jydjAdapter adapter;
    @Override
    protected void initEnvironment() {

    }

    @Override
    protected void initViews() {
        mLtitle=findViewById(R.id.in_jydj_title)  ;
        mImageBack=(ImageButton)  mLtitle.findViewById(R.id.img_title_back);
        mTextTitle=(TextView)  mLtitle.findViewById(R.id.tv_include_title);
        mTextTitle.setText("检验查询");
        mImageBack.setOnClickListener(this);
      mNodata=findViewById(R.id.tv_jysq_null) ;
      mNodata.setVisibility(View.GONE);
      mLjydj=findViewById(R.id.ll_jydj);
      mLjydj.setVisibility(View.GONE);
      mListView=findViewById(R.id.list_jydj);

   final Bundle bundle=this.getIntent().getExtras();
   String cardNo=bundle.getString("cardNo");
        Lis_jysqRequest request=new Lis_jysqRequest();
        request.setCardNo(cardNo);
        request.setDeviceId("0");
        String js= JSON.toJSONString(request);
        String url=APP_URL+"/GetLisJysq";
        OkGo.<GetLisJysqResponse>post(url).upJson(js).execute(new JsonCallback<GetLisJysqResponse>() {
            @Override
            public void onSuccess(Response<GetLisJysqResponse> response) {
                GetLisJysqResponse response1=response.body();
                if (response1.getResultCode().equals("0")) {
                    if(response1.getItems()!=null&&!response1.getItems().isEmpty()){
                        final List<Lis_jysqList> mdata=response1.getItems();
                       adapter=new Lis_jydjAdapter(Lis_JydjActivity.this,mdata);
                       mListView.setAdapter(adapter);
                       mLjydj.setVisibility(View.VISIBLE);
                       mNodata.setVisibility(View.GONE);
                       mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                           @Override
                           public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                               Lis_jysqList mda=new Lis_jysqList();
                                     mda= mdata.get(position);
                               Intent intent=new Intent();
                               Bundle bundle1=new Bundle();
                               intent.setClass(Lis_JydjActivity.this,Lis_mxActivity.class);
                                bundle1.putSerializable("info",mda);
                                intent.putExtras(bundle1);
                            //   intent.putExtra("info", mda);
                               startActivity(intent);
                           }
                       });
                    }
                    else { mLjydj.setVisibility(View.GONE);
                        mNodata.setVisibility(View.VISIBLE);}
                }
                else {
                    Toast.makeText(Lis_JydjActivity.this,response1.getResultMsg(),Toast.LENGTH_LONG).show();
                }
                }
            }
        );
    }

    @Override
    protected int getLayoutId() {
        return (R.layout.activity_lis__jydj);
    }


    @Override
    public void onClick(View v) {

    }
}
